/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import clases.ClsDatabase;
import clases.ClsMetodos;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author casa
 */
public class dlgPartidasLista extends javax.swing.JDialog {

    private ClsMetodos metodos = new ClsMetodos();
    private ClsDatabase bd = new ClsDatabase();
    /**
     * Creates new form dlgPartidasLista
     */
    String idproyecto = "";
    String idinsumo = "";

    public dlgPartidasLista(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        iniciar();
    }

    public dlgPartidasLista(java.awt.Dialog parent, boolean modal, String idproyecto_d, String idinsumo_d) {
        super(parent, modal);
        initComponents();
        idproyecto = idproyecto_d;
        idinsumo = idinsumo_d;
        iniciar();
    }

    public void iniciar() {
        setLocationRelativeTo(null);
        metodos.tablaLongitudColumnas(tblInsumos, new int[]{0, 15, 70, 390});
        metodos.tablaOcultarcolumnas(tblInsumos, new int[]{0});
        metodos.tablaLlenaSql_defecto(tblInsumos, " pp.item,'',CONCAT(pr.orden,'.',pp.item), p.nombre ", " FROM presupuesto pr, presupuesto_partida pp,partida_base p,partida_base_detalle pd\n"
                + "where  pr.idproyecto=pp.idproyecto and pr.idpresupuesto=pp.idpresupuesto and pp.idpartida=p.idpartida and p.idpartida=pd.idpartida and pp.idproyecto='" + idproyecto + "' and pd.idinsumo='" + idinsumo + "'\n"
                + "group by pr.orden,pp.item,p.nombre\n"
                + "order by pr.orden asc,pp.item, p.nombre asc;");
        alinear_tabla();

        tblInsumos.setShowGrid(true);
        tblInsumos.setShowVerticalLines(true);
        //tblInsumos.setGridColor(Color.red);

        metodos.tablaNumeracion(tblInsumos, new int[]{1});
        btnEditarACU.setVisible(false);
    }

    public void alinear_tabla() {

        DefaultTableCellRenderer modelocentrar_color_1 = new DefaultTableCellRenderer();
        modelocentrar_color_1.setBackground(new java.awt.Color(166, 166, 166));
        tblInsumos.getColumnModel().getColumn(1).setCellRenderer(modelocentrar_color_1);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnEditarACU = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblInsumos = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Partidas del Insumo");

        jPanel1.setBackground(new java.awt.Color(225, 235, 247));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnEditarACU.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/icon/principales/peque/editar.png"))); // NOI18N
        btnEditarACU.setText("Editar");
        btnEditarACU.setFocusable(false);
        btnEditarACU.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEditarACU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarACUActionPerformed(evt);
            }
        });
        jPanel1.add(btnEditarACU, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 110, 30));

        tblInsumos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Cód.", "N°", "Item", "Partida"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblInsumos.setRowHeight(23);
        tblInsumos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblInsumos.getTableHeader().setReorderingAllowed(false);
        tblInsumos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblInsumosMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tblInsumos);

        jPanel1.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 520, 260));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/icon/principales/peque/salir.png"))); // NOI18N
        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 300, 102, -1));

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/icon/principales/fondo_dialog.jpg"))); // NOI18N
        jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 450, 330));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblInsumosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblInsumosMouseClicked
    }//GEN-LAST:event_tblInsumosMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnEditarACUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarACUActionPerformed
    }//GEN-LAST:event_btnEditarACUActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgPartidasLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgPartidasLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgPartidasLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgPartidasLista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgPartidasLista dialog = new dlgPartidasLista(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEditarACU;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable tblInsumos;
    // End of variables declaration//GEN-END:variables
}
